home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-05
/
rje.zip
/
RJE.C
< prev
next >
Wrap
Text File
|
1992-11-28
|
7KB
|
170 lines
/* ************************************************************************* */
/* RJE - Remote Job Entry Facility for peer-to-peer networks */
/* */
/* For use with Douglas Boling's REDD utility (from PC magazine) */
/* */
/* Usage: RJE [-s control file] | <command> <parameters...> */
/* */
/* if -s option is used, then "control file" is a standard batch */
/* file. Otherwise rje expects a single command with optional */
/* parameters. */
/* */
/* Notes and Caveats: */
/* */
/* This code was compiled using Borland's Turbo C++ V1.0. It will not */
/* compile with MS C 5.1 unless you supply an equivalent for the "delay" */
/* function (it ain't hard, but I'll leave it as an exercise for you). */
/* */
/* A guiding paradigm here is the notion that the network will contain one */
/* one servers, which don't get used for anything but RJE and LAN file */
/* transactions. It would be unnerving for someone using the server to */
/* suddenly see a "mystery command" appear out of nowhere - especially in */
/* the middle of a word processing session. Upshot: dedicate a server. */
/* */
/* rje expects to find an environment variable in the workstations global */
/* exvironment space called "rje", which contains the REDD network drive */
/* letter in the form <drive>: */
/* */
/* Note that the trailing colon is not optional; rje will whine about it if */
/* it is not supplied. */
/* */
/* rje will not overwrite an existing REDD keyboard.in control file. It will */
/* retry the operation for a few seconds before giving up. This allows for */
/* multiple users to gain access to the REDD facility. */
/* */
/* Some replacement ANSI screen drivers seem to cause REDD some grief. Use */
/* the orginal PC/MS-DOS ANSI.SYS on your server, or use nothing at all */
/* (after all, it's a server, right?) */
/* */
/* This code is not elegant. Do with it as you will. I don't even want any */
/* credit for it. */
/* */
/* rje is successfully running on an Artisoft LAN. It has not been tested on */
/* any other network. */
/* */
/* created 11/92 by John M. Hughes - jmh%cerberus.uucp@noao.uucp */
/* jmh@coyote.datalog.com */
/* BIX: jmh */
/* Compuserve: 70521,1276 */
/* */
/* p.s. Please don't plague me with bug reports - you have the source code. */
/* ************************************************************************* */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dos.h>
#include <sys\stat.h>
FILE *src, *targ, *outfile;
char tmp[256];
char rjetarg[33];
struct stat statbuf;
int i;
void submit(char *subname)
{
if (stat(subname,&statbuf) != 0) {
printf("Error - Submit file not found\n");
exit(1);
}
if (statbuf.st_size == 0) {
printf("Error - Empty submit file\n");
exit(1);
}
if (stat(rjetarg,&statbuf) == 0) {
printf("RJE Facility Currently In Use - Retrying...\n");
i = 0;
again1:
if (stat(rjetarg,&statbuf) == 0) {
delay(500);
if (i > 10) {
printf("CANNOT SUBMIT JOB - RJE Facility Busy\n");
exit(3);
}
i++;
}
else
goto again1;
}
if ((targ = fopen(rjetarg,"w")) == NULL) {
printf("Error - could not open RJE target\n");
exit(1);
}
if ((src = fopen(subname,"r")) == NULL) {
printf("Error - could not open RJE source\n");
fclose(targ);
exit(1);
}
while (!feof(src))
if (fgets(tmp,100,src)) fputs(tmp,targ);
fclose(targ);
fclose(src);
remove(subname);
}
void main(int argc, char *argv[])
{
char outname[32] = "rjein.tmp";
if (argc < 2) {
printf("Error - Invalid Command Line\n\n");
printf("Usage: RJE [-s control file] | <command> <parameters...>\n\n");
exit(1);
}
if (getenv("RJE")) {
strcpy(rjetarg,getenv("RJE"));
if (rjetarg[1] != ':') {
printf("Error - invalid target drive format in environment\n");
exit(1);
}
strcat(rjetarg,"keyboard.in");
}
else {
printf("Error - RJE target drive not in environment\n");
exit(1);
}
if (!strcmp("-s",argv[1]) || !strcmp("-S",argv[1])) {
if (argc < 3) {
printf("Error - No submit file specified\n");
exit(1);
}
submit(argv[2]);
}
else {
if ((outfile = fopen(outname,"w")) == NULL) {
printf("Error - Unable to create RJE control output file\n");
exit(2);
}
/* build command string */
strcpy(tmp,argv[1]);
if (argc >2)
for (i=2;i<argc;i++) {
strcat(tmp," ");
strcat(tmp,argv[i]);
}
fprintf(outfile,"%s\n",tmp);
fclose(outfile);
/* send the rje file for execution */
submit(outname);
}
printf("Job Submitted OK\n");
exit(0);
}